From: Ian Campbell Date: Wed, 28 Sep 2011 15:34:00 +0000 (+0100) Subject: libxl: correct allocation size in libxl_list_vm X-Git-Tag: archive/raspbian/4.8.0-1+rpi1~1^2~9855 X-Git-Url: https://dgit.raspbian.org/%22http://www.example.com/cgi/success//%22http:/www.example.com/cgi/success/?a=commitdiff_plain;h=03744e707be948416fabade6fe027a2c4fa2397e;p=xen.git libxl: correct allocation size in libxl_list_vm *ptr has type libxl_vminfo not libxl_domid, so correct calloc call. This the second instance of this bug I've noticed recently, I did a quick audit of other similar uses of sizeof(...) and all I spotted were a couple of harmlessly reversed calloc arguments. It's a pretty strong argument for "foo = ..alloc(sizeof(*foo))" rather than "alloc(sizeof(foos_type))" though... Signed-off-by: Ian Campbell Acked-by: Ian Jackson Committed-by: Ian Jackson --- diff --git a/tools/libxl/libxl.c b/tools/libxl/libxl.c index 36ad1f1a97..3dc7b5be9e 100644 --- a/tools/libxl/libxl.c +++ b/tools/libxl/libxl.c @@ -449,7 +449,7 @@ libxl_vminfo * libxl_list_vm(libxl_ctx *ctx, int *nb_vm) xc_domaininfo_t info[1024]; int size = 1024; - ptr = calloc(size, sizeof(libxl_dominfo)); + ptr = calloc(size, sizeof(libxl_vminfo)); if (!ptr) return NULL; diff --git a/tools/libxl/libxl_dm.c b/tools/libxl/libxl_dm.c index 254f016889..c575460595 100644 --- a/tools/libxl/libxl_dm.c +++ b/tools/libxl/libxl_dm.c @@ -774,7 +774,7 @@ retry_transaction: libxl_domain_unpause(ctx, domid); if (starting_r) { - *starting_r = calloc(sizeof(libxl__device_model_starting), 1); + *starting_r = calloc(1, sizeof(libxl__device_model_starting)); (*starting_r)->domid = info->domid; (*starting_r)->dom_path = libxl__xs_get_dompath(gc, info->domid); (*starting_r)->for_spawn = NULL; @@ -851,11 +851,11 @@ int libxl__create_device_model(libxl__gc *gc, if (starting_r) { rc = ERROR_NOMEM; - *starting_r = calloc(sizeof(libxl__device_model_starting), 1); + *starting_r = calloc(1, sizeof(libxl__device_model_starting)); if (!*starting_r) goto out_close; p = *starting_r; - p->for_spawn = calloc(sizeof(libxl__spawn_starting), 1); + p->for_spawn = calloc(1, sizeof(libxl__spawn_starting)); } else { p = &buf_starting; p->for_spawn = NULL;